﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using dotnet_learn.Dao;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

namespace dotnet_learn.Controllers
{



    [Route("api/[controller]")]
    [ApiController]
    public class ValuesController : ControllerBase
    {

    //private readonly ILogger _logger;


        // GET api/values
        [HttpGet]
        public ActionResult<IEnumerable<string>> Get()
        {
            return new string[] { "value1", "value2" };
        }

        // GET api/values/5
        [HttpGet("{id}")]
        public ActionResult<string> Get(int id)
        {
            return "value";
        }

        // POST api/values
        [HttpPost]
        public void Post([FromBody] string value)
        {
            
        }

         // POST api/user
        [HttpPost("/api/user")]
        public ActionResult<UserRes> PostUser(UserReq req)
        {
            Console.WriteLine("name="+req.name);
            
            LogHelper.Write(req.name,LogLev.Debug);

             
            //_logger.LogInformation("Message displayed:");

            return new UserRes(){
                name="name is "+ req.name,
                age = req.age
            };
        }

        public class UserReq{
            public string name {get;set;}

            public int age {get;set;}
        }

        public class UserRes{
            public string name {get;set;}

            public int age {get;set;}

            public string msg {get;set;}="success";
        }

        // PUT api/values/5
        [HttpPut("{id}")]
        public void Put(int id, [FromBody] string value)
        {
        }

        // DELETE api/values/5
        [HttpDelete("{id}")]
        public void Delete(int id)
        {
        }
    }
}
